//
//  HomeOrderInfoController.m
//  RentTable
//
//  Created by mac on 2024/11/30.
//

#import "HomeOrderInfoController.h"
#import "ReviewOrderView.h"
#import "OrderInfoView.h"
#import "RentRuleView.h"

@interface HomeOrderInfoController ()

@property (nonatomic, strong) ReviewOrderView *reviewOrderView;
@property (nonatomic, strong) OrderInfoView *orderInfoView;
@property (nonatomic, strong) RentRuleView *orderRuleView;

@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *addressLabel;

@property (nonatomic, strong) UIButton *cancelButton;

@end

@implementation HomeOrderInfoController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setUI];
}

- (void)setUI {
    self.view.backgroundColor = myRGBHex(0xFFFFFF);
    [self loadBackArrow];
    [self loadTitle:@"订单详情"];
    [self loadDevide];
    
    UIView *orderBackView = [UIView new];
    orderBackView.backgroundColor = myRGBHex(0xFFFFFF);
    [self.view addSubview:orderBackView];
    [orderBackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(0);
        make.height.mas_equalTo(359 * scaleH);
        make.top.mas_equalTo(89 * scaleH);
    }];
    
    UIView *orderView = [UIView new];
    orderView.backgroundColor = myRGBHex(0xFF0AA1);
    [orderBackView addSubview:orderView];
    [orderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(10);
        make.leading.mas_equalTo(16);
        make.size.mas_equalTo(CGSizeMake(6, 19 * scaleH));
    }];
    
    UILabel *sumLabel = [[UILabel alloc] init];
    sumLabel.text = @"订单详情";
    sumLabel.font = [UIFont pingFangSCRegularWithSize:17];
    sumLabel.textColor = myRGBHex(0x333333);
    [orderBackView addSubview:sumLabel];
    [sumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(orderView.mas_centerY);
        make.leading.equalTo(orderView.mas_trailing).offset(18);
        make.height.mas_equalTo(21 * scaleH);
    }];
    
    UILabel *numLabel = [[UILabel alloc] init];
    numLabel.text = @"共1件商品";
    numLabel.font = [UIFont pingFangSCRegularWithSize:14];
    numLabel.textColor = myRGBHex(0x333333);
    [orderBackView addSubview:numLabel];
    [numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(orderView.mas_bottom).offset(10 * scaleH);
        make.leading.mas_equalTo(17);
        make.height.mas_equalTo(18 * scaleH);
    }];
    
    
    self.reviewOrderView = [ReviewOrderView new];
    [orderBackView addSubview:self.reviewOrderView];
    self.reviewOrderView.rentModel = self.rentModel;
    [self.reviewOrderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(0);
        make.top.equalTo(numLabel.mas_bottom).offset(5 * scaleH);
        make.height.mas_equalTo(135 * scaleH);
    }];
    
    NSDictionary *orderInfo = @{
        @"订单编号" : self.rentModel.rentOrderNumber,
        @"下单时间" : self.rentModel.rentOrderTime,
        @"押金金额：" : @"¥2000",
        @"实付合计：" : [NSString stringWithFormat:@"¥%.0f",(self.rentModel.rentPrice * self.rentModel.rentCount * self.rentModel.rentPeriod * 30 + 2000)]
    };
    self.orderInfoView = [[OrderInfoView alloc] initWithFrame:CGRectZero orderInfo:orderInfo];
    [orderBackView addSubview:self.orderInfoView];
    [self.orderInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.reviewOrderView.mas_bottom).offset(10 * scaleH);
        make.leading.trailing.mas_equalTo(0);
        make.bottom.mas_equalTo(-6 * scaleH);
    }];
    
    UIView *midDevideView = [UIView new];
    midDevideView.backgroundColor = myRGBHexAlpha(0xCCCCCC, 0.3);
    [self.view addSubview:midDevideView];
    [midDevideView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(0);
        make.height.mas_equalTo(8 * scaleH);
        make.top.equalTo(orderBackView.mas_bottom);
    }];
    
    self.nameLabel = [[UILabel alloc] init];
    self.nameLabel.text = [NSString stringWithFormat:@"%@\t%@",self.rentModel.rentConsignee,self.rentModel.rentContactInfo];
    self.nameLabel.textColor = myRGBHex(0x333333);
    self.nameLabel.font = [UIFont pingFangSCMediumWithSize:13];
    self.nameLabel.textColor = myRGBHex(0x666666);
    [self.view addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(16);
        make.top.equalTo(midDevideView.mas_bottom).offset(12 * scaleH);
        make.trailing.mas_equalTo(-16);
    }];
    
    
    self.addressLabel = [[UILabel alloc] init];
    self.addressLabel.text = self.rentModel.rentReceAddress;
    self.addressLabel.textColor = myRGBHex(0x333333);
    self.addressLabel.font = [UIFont pingFangSCMediumWithSize:13];
    self.addressLabel.textColor = myRGBHex(0x666666);
    [self.view addSubview:self.addressLabel];
    [self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(16);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(8 * scaleH);
        make.trailing.mas_equalTo(-16);
    }];
    
    UIView *botdDevideView = [UIView new];
    botdDevideView.backgroundColor = myRGBHexAlpha(0xCCCCCC, 0.3);
    [self.view addSubview:botdDevideView];
    [botdDevideView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(0);
        make.height.mas_equalTo(8 * scaleH);
        make.top.equalTo(self.addressLabel.mas_bottom).offset(12 * scaleH);
    }];
    
    self.orderRuleView = [RentRuleView new];
    [self.view addSubview:self.orderRuleView];
    [self.orderRuleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(botdDevideView.mas_bottom).offset(8);
        make.leading.trailing.mas_equalTo(0);
        make.height.mas_equalTo(167 * scaleH);
    }];
    
    self.cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.cancelButton setTitle:@"取消订单" forState:UIControlStateNormal];
    [self.cancelButton setTitleColor:myRGBHex(0x999999) forState:UIControlStateNormal];
    self.cancelButton.titleLabel.font = [UIFont pingFangSCRegularWithSize:16];
    [self.cancelButton addTarget:self action:@selector(cancelButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.cancelButton];
    [self.cancelButton.titleLabel sizeToFit];
    self.cancelButton.layer.cornerRadius = 5;
    self.cancelButton.layer.borderColor = myRGBHex(0x999999).CGColor;
    self.cancelButton.layer.borderWidth = 0.5;
    self.cancelButton.layer.masksToBounds = true;
    [self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-30 * scaleH);
        make.trailing.mas_equalTo(-17);
        make.size.mas_equalTo(CGSizeMake(91, 32));
    }];
}

- (void)cancelButtonPressed:(UIButton *)sender {
    [self.navigationController popToRootViewControllerAnimated:false];
    [RentModelManager removeRentModelByRentBuyId:self.rentModel.rentBuyId];
}

@end
